package com.cxh.supermarket.common.config;

import com.aliyun.dypnsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云一键登陆参数配置
 *
 * @author zxl
 * @version 2024/1/22
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "oneclick")
public class AppOneClickLoginProperties implements InitializingBean {

    /**
     * key
     */
    private String accessKeyID;
    /**
     * 密匙
     */
    private String accessKeySecret;

    /**
     * key常量
     */
    public static String ACCESS_KEY_ID;
    /**
     * 密匙常量
     */
    public static String ACCESS_KEY_SECRET;

    @Override
    public void afterPropertiesSet() {
        ACCESS_KEY_ID = this.accessKeyID;
        ACCESS_KEY_SECRET = this.accessKeySecret;
    }

    @Bean
    public Client client() throws Exception {
        Config config = new Config()
            // 必填，您的 AccessKey ID
            .setAccessKeyId(ACCESS_KEY_ID)
            // 必填，您的 AccessKey Secret
            .setAccessKeySecret(ACCESS_KEY_SECRET);
        // 访问的域名
        config.endpoint = "dypnsapi.aliyuncs.com";
        return new Client(config);
    }
}
